﻿@using WaterRevenueMS.Domain.ViewModels.DataAuditing;
@using WaterRevenueMS.Domain.ViewModels.AdminCommon
@model DataAuditingModel
@{
    ViewBag.Title = ViewBag.CurrentTitle + " - 潍微水务管理系统";
    var editButton = new ButtonModel();
    var deleteButton = new ButtonModel();
    editButton = ViewBag.Edit;
    deleteButton = ViewBag.Delete;
}
@section css{
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.core.css")" rel="Stylesheet" type="text/css"/>  
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.autocomplete.css")" rel="Stylesheet" type="text/css"/> 
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.datepicker.css")" rel="Stylesheet" type="text/css"/> 
     <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="Stylesheet" type="text/css"/> 
}

<div id="content-body" class="row-fluid">
    <div class="span22">
        <!--操作 -->
        @Html.Partial("Search", Model.Search)

        <!--列表-->
        @Html.Partial("List")

        <!--新增 & 编辑-->
        @Html.Partial("_FormModal")

        <!--用量减免-->
        @Html.Partial("_FormModalConsumptionAdjust")
    
    </div>
</div>

@section scripts{
    <script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui-zh.js")" type="text/javascript"></script>
    <script type="text/javascript">
        var oTable = null;

        $(function () {
            var actionUrl = "@Url.Action("List")?rand=" + Math.random();
            var aoColumns = [
                    { "sName": "SortId", "bSortable": false },
                    
                    { "sName": "CustomerName", "bSortable": false },
                    { "sName": "CustomerNo", "bSortable": false },
                    { "sName": "MeterNo", "bSortable": false },
                    { "sName": "Yong_LBC", "bSortable": false },
                    {
                        "sName": "Id",
                        "bSearchable": false,
                        "bSortable": false,
                        "fnRender": function (oObj) {
                            var btnArray = "";

                            btnArray += '<button type="submit" class="btn btn-primary btn-normal" title="加减水量" onclick="ConsumptionAdjust(' + oObj.aData[oObj.aData.length - 1] + ')">加减水量</button>';
                            btnArray += '<button type="submit" class="btn btn-primary btn-normal" title="水费减免" onclick="WaterChargeAdjust(' + oObj.aData[oObj.aData.length - 1] + ')">水费减免</button>';
                            return btnArray;
                        }
                    }
            ];
            //初始化表格
            oTable = InitDatatables($(".data-table"), actionUrl, aoColumns, oTable);
        });

                //查询
        function Search() {
            var filterdata = $(".search-form").serialize();
            var actionUrl = "@Url.Action("List")?rand=" + Math.random() + "&" + filterdata;
            SearchRecord(actionUrl, oTable);
        }
        //用量调整
        function ConsumptionAdjust(id)
        {
            var actionUrl="@Url.Action("ConsumptionAdjust")";
            var param={Id:id};
            $(".modal-title-DataAuditing").html("用量调整");
            $("#modal-content-DataAuditing").attr("action", actionUrl);
    
            $.ajax({
                type: "GET",
                url: actionUrl,
                data: param,
                success: function (result) {
                    $("#modal-content-DataAuditing").html(result);
                    $('#modal-form-DataAuditing').modal('show');
                    
                },
                error: function () {
                    //
                },
                complete: function () {
                    //
                }
            });
        }
        //水费调整
        function WaterChargeAdjust(id)
        {
            var actionUrl="@Url.Action("WaterChargeAdjust")";
            var param={Id:id};
            ShowModal(actionUrl,param,"水费调整");
        }


        //保存
        function Save() {
            SaveModal(oTable);
        }

        //删除
        function Delete(id) {
            var actionUrl = "@Url.Action("Delete")";
            var param = { Id: id }
            DeleteRecord(actionUrl, param, oTable);
        }

        function SaveDataAuditing()
        {
            var actionUrl = $("#modal-content-DataAuditing").attr("action");
            var $form = $("#modal-content-DataAuditing");

            if (!$form.valid()) {
                return;
            }

            $.ajax({
                type: "POST",
                url: actionUrl,
                data: $form.serialize(),
                success: function (data) {
                    //判断返回值，若为Object类型，即操作成功
                    var result = ((typeof data == 'object') && (data.constructor == Object));
                    if (result) {
                        bootbox.alert(data.Message);
                        $('#modal-form-DataAuditing').modal('hide');
                        //ReloadDataTable(oTable);
                    }
                    else {
                        $("#modal-content-DataAuditing").html(data);
                    }
                }
            });
        }

        function CloseDataAuditingModal()
        {
            $('#modal-form-DataAuditing').modal('hide');
            ClearForm($("#modal-content-DataAuditing"));
        }
    </script>
}

